package com.hmy.security.security.bean;

import com.hmy.security.entity.Menu;
import com.hmy.security.entity.Roles;
import lombok.Data;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;
import java.util.List;

@Data
public class JwtUser implements UserDetails {

    /** uid */
    private Long uid;

    /** 用户名 */
    private String username;

    /** 密码 */
    private String password;

    /** 角色信息 */
    private Collection<SimpleGrantedAuthority> authorities;

    /** 所具备角色列表 */
    private List<Roles> roles;

    /** 所具备权限的菜单 */
    private List<Menu> menus;

    /**
     * 获取当前用户所具有的所有角色信息
     * @return {@link Collection}
     */
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return authorities;
    }

    /**
     * 获取当前用户的密码
     * @return {@link String}
     */
    public String getPassword() {
        return password;
    }

    /**
     * 获取当前用户的用户名
     * @return {@link String}
     */
    public String getUsername() {
        return username;
    }

    /**
     * 当前账户是否未过期
     * @return {@link Boolean}
     */
    public boolean isAccountNonExpired() {
        return true;
    }

    /**
     * 当前账户是否未被锁定
     * @return {@link Boolean}
     */
    public boolean isAccountNonLocked() {
        return true;
    }

    /**
     * 当前账户密码是否未过期
     * @return {@link Boolean}
     */
    public boolean isCredentialsNonExpired() {
        return true;
    }

    /**
     * 当前账户是否可用
     * @return {@link Boolean}
     */
    public boolean isEnabled() {
        return true;
    }
}
